home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / ZODB / interfaces.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  17.7 KB  |  426 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Interfaces for ZODB.
  5.  
  6. $Id: interfaces.py 38095 2005-08-25 23:03:29Z tim_one $
  7. '''
  8. from zope.interface import Interface, Attribute
  9.  
  10. class IConnection(Interface):
  11.     '''Connection to ZODB for loading and storing objects.
  12.  
  13.     The Connection object serves as a data manager.  The root() method
  14.     on a Connection returns the root object for the database.  This
  15.     object and all objects reachable from it are associated with the
  16.     Connection that loaded them.  When a transaction commits, it uses
  17.     the Connection to store modified objects.
  18.  
  19.     Typical use of ZODB is for each thread to have its own
  20.     Connection and that no thread should have more than one Connection
  21.     to the same database.  A thread is associated with a Connection by
  22.     loading objects from that Connection.  Objects loaded by one
  23.     thread should not be used by another thread.
  24.  
  25.     A Connection can be associated with a single version when it is
  26.     created.  By default, a Connection is not associated with a
  27.     version; it uses non-version data.
  28.  
  29.     Each Connection provides an isolated, consistent view of the
  30.     database, by managing independent copies of objects in the
  31.     database.  At transaction boundaries, these copies are updated to
  32.     reflect the current state of the database.
  33.  
  34.     You should not instantiate this class directly; instead call the
  35.     open() method of a DB instance.
  36.  
  37.     In many applications, root() is the only method of the Connection
  38.     that you will need to use.
  39.  
  40.     Synchronization
  41.     ---------------
  42.  
  43.     A Connection instance is not thread-safe.  It is designed to
  44.     support a thread model where each thread has its own transaction.
  45.     If an application has more than one thread that uses the
  46.     connection or the transaction the connection is registered with,
  47.     the application should provide locking.
  48.  
  49.     The Connection manages movement of objects in and out of object
  50.     storage.
  51.  
  52.     TODO:  We should document an intended API for using a Connection via
  53.     multiple threads.
  54.  
  55.     TODO:  We should explain that the Connection has a cache and that
  56.     multiple calls to get() will return a reference to the same
  57.     object, provided that one of the earlier objects is still
  58.     referenced.  Object identity is preserved within a connection, but
  59.     not across connections.
  60.  
  61.     TODO:  Mention the database pool.
  62.  
  63.     A database connection always presents a consistent view of the
  64.     objects in the database, although it may not always present the
  65.     most current revision of any particular object.  Modifications
  66.     made by concurrent transactions are not visible until the next
  67.     transaction boundary (abort or commit).
  68.  
  69.     Two options affect consistency.  By default, the mvcc and synch
  70.     options are enabled by default.
  71.  
  72.     If you pass mvcc=False to db.open(), the Connection will never read
  73.     non-current revisions of an object.  Instead it will raise a
  74.     ReadConflictError to indicate that the current revision is
  75.     unavailable because it was written after the current transaction
  76.     began.
  77.  
  78.     The logic for handling modifications assumes that the thread that
  79.     opened a Connection (called db.open()) is the thread that will use
  80.     the Connection.  If this is not true, you should pass synch=False
  81.     to db.open().  When the synch option is disabled, some transaction
  82.     boundaries will be missed by the Connection; in particular, if a
  83.     transaction does not involve any modifications to objects loaded
  84.     from the Connection and synch is disabled, the Connection will
  85.     miss the transaction boundary.  Two examples of this behavior are
  86.     db.undo() and read-only transactions.
  87.  
  88.     Groups of methods:
  89.  
  90.         User Methods:
  91.             root, get, add, close, db, sync, isReadOnly, cacheGC, cacheFullSweep,
  92.             cacheMinimize, getVersion, modifiedInVersion
  93.  
  94.         Experimental Methods:
  95.             onCloseCallbacks
  96.  
  97.         Database Invalidation Methods:
  98.             invalidate
  99.  
  100.         Other Methods: exchange, getDebugInfo, setDebugInfo,
  101.             getTransferCounts
  102.     '''
  103.     
  104.     def add(ob):
  105.         """Add a new object 'obj' to the database and assign it an oid.
  106.  
  107.         A persistent object is normally added to the database and
  108.         assigned an oid when it becomes reachable to an object already in
  109.         the database.  In some cases, it is useful to create a new
  110.         object and use its oid (_p_oid) in a single transaction.
  111.  
  112.         This method assigns a new oid regardless of whether the object
  113.         is reachable.
  114.  
  115.         The object is added when the transaction commits.  The object
  116.         must implement the IPersistent interface and must not
  117.         already be associated with a Connection.
  118.  
  119.         Parameters:
  120.         obj: a Persistent object
  121.  
  122.         Raises TypeError if obj is not a persistent object.
  123.  
  124.         Raises InvalidObjectReference if obj is already associated with another
  125.         connection.
  126.  
  127.         Raises ConnectionStateError if the connection is closed.
  128.         """
  129.         pass
  130.  
  131.     
  132.     def get(oid):
  133.         """Return the persistent object with oid 'oid'.
  134.  
  135.         If the object was not in the cache and the object's class is
  136.         ghostable, then a ghost will be returned.  If the object is
  137.         already in the cache, a reference to the cached object will be
  138.         returned.
  139.  
  140.         Applications seldom need to call this method, because objects
  141.         are loaded transparently during attribute lookup.
  142.  
  143.         Parameters:
  144.         oid: an object id
  145.  
  146.         Raises KeyError if oid does not exist.
  147.  
  148.             It is possible that an object does not exist as of the current
  149.             transaction, but existed in the past.  It may even exist again in
  150.             the future, if the transaction that removed it is undone.
  151.  
  152.         Raises ConnectionStateError if the connection is closed.
  153.         """
  154.         pass
  155.  
  156.     
  157.     def cacheMinimize():
  158.         '''Deactivate all unmodified objects in the cache.
  159.  
  160.         Call _p_deactivate() on each cached object, attempting to turn
  161.         it into a ghost.  It is possible for individual objects to
  162.         remain active.
  163.         '''
  164.         pass
  165.  
  166.     
  167.     def cacheGC():
  168.         '''Reduce cache size to target size.
  169.  
  170.         Call _p_deactivate() on cached objects until the cache size
  171.         falls under the target size.
  172.         '''
  173.         pass
  174.  
  175.     
  176.     def onCloseCallback(f):
  177.         '''Register a callable, f, to be called by close().
  178.  
  179.         f will be called with no arguments before the Connection is closed.
  180.  
  181.         Parameters:
  182.         f: method that will be called on `close`
  183.         '''
  184.         pass
  185.  
  186.     
  187.     def close():
  188.         """Close the Connection.
  189.  
  190.         When the Connection is closed, all callbacks registered by
  191.         onCloseCallback() are invoked and the cache is garbage collected.
  192.  
  193.         A closed Connection should not be used by client code.  It can't load
  194.         or store objects.  Objects in the cache are not freed, because
  195.         Connections are re-used and the cache is expected to be useful to the
  196.         next client.
  197.         """
  198.         pass
  199.  
  200.     
  201.     def db():
  202.         '''Returns a handle to the database this connection belongs to.'''
  203.         pass
  204.  
  205.     
  206.     def isReadOnly():
  207.         '''Returns True if the storage for this connection is read only.'''
  208.         pass
  209.  
  210.     
  211.     def invalidate(tid, oids):
  212.         """Notify the Connection that transaction 'tid' invalidated oids.
  213.  
  214.         When the next transaction boundary is reached, objects will be
  215.         invalidated.  If any of the invalidated objects are accessed by the
  216.         current transaction, the revision written before Connection.tid will be
  217.         used.
  218.  
  219.         The DB calls this method, even when the Connection is closed.
  220.  
  221.         Parameters:
  222.         tid: the storage-level id of the transaction that committed
  223.         oids: oids is a set of oids, represented as a dict with oids as keys.
  224.         """
  225.         pass
  226.  
  227.     
  228.     def root():
  229.         '''Return the database root object.
  230.  
  231.         The root is a persistent.mapping.PersistentMapping.
  232.         '''
  233.         pass
  234.  
  235.     
  236.     def getVersion():
  237.         '''Returns the version this connection is attached to.'''
  238.         pass
  239.  
  240.     connections = Attribute('        A mapping from database name to a Connection to that database.\n\n        In multi-database use, the Connections of all members of a database\n        collection share the same .connections object.\n\n        In single-database use, of course this mapping contains a single\n        entry.\n        ')
  241.     
  242.     def get_connection(database_name):
  243.         """Return a Connection for the named database.
  244.  
  245.         This is intended to be called from an open Connection associated with
  246.         a multi-database.  In that case, database_name must be the name of a
  247.         database within the database collection (probably the name of a
  248.         different database than is associated with the calling Connection
  249.         instance, but it's fine to use the name of the calling Connection
  250.         object's database).  A Connection for the named database is
  251.         returned.  If no connection to that database is already open, a new
  252.         Connection is opened.  So long as the multi-database remains open,
  253.         passing the same name to get_connection() multiple times returns the
  254.         same Connection object each time.
  255.         """
  256.         pass
  257.  
  258.     
  259.     def sync():
  260.         '''Manually update the view on the database.
  261.  
  262.         This includes aborting the current transaction, getting a fresh and
  263.         consistent view of the data (synchronizing with the storage if
  264.         possible) and calling cacheGC() for this connection.
  265.  
  266.         This method was especially useful in ZODB 3.2 to better support
  267.         read-only connections that were affected by a couple of problems.
  268.         '''
  269.         pass
  270.  
  271.     
  272.     def getDebugInfo():
  273.         '''Returns a tuple with different items for debugging the connection.
  274.  
  275.         Debug information can be added to a connection by using setDebugInfo.
  276.         '''
  277.         pass
  278.  
  279.     
  280.     def setDebugInfo(*items):
  281.         '''Add the given items to the debug information of this connection.'''
  282.         pass
  283.  
  284.     
  285.     def getTransferCounts(clear = False):
  286.         '''Returns the number of objects loaded and stored.
  287.  
  288.         If clear is True, reset the counters.
  289.         '''
  290.         pass
  291.  
  292.  
  293.  
  294. class IDatabase(Interface):
  295.     '''ZODB DB.
  296.  
  297.     TODO: This interface is incomplete.
  298.     '''
  299.     
  300.     def __init__(storage, pool_size = 7, cache_size = 400, version_pool_size = 3, version_cache_size = 100, database_name = 'unnamed', databases = None):
  301.         """Create an object database.
  302.  
  303.         storage: the storage used by the database, e.g. FileStorage
  304.         pool_size: expected maximum number of open connections
  305.         cache_size: target size of Connection object cache, in number of
  306.             objects
  307.         version_pool_size: expected maximum number of connections (per
  308.             version)
  309.         version_cache_size: target size of Connection object cache for
  310.              version connections, in number of objects
  311.         database_name: when using a multi-database, the name of this DB
  312.             within the database group.  It's a (detected) error if databases
  313.             is specified too and database_name is already a key in it.
  314.             This becomes the value of the DB's database_name attribute.
  315.         databases: when using a multi-database, a mapping to use as the
  316.             binding of this DB's .databases attribute.  It's intended
  317.             that the second and following DB's added to a multi-database
  318.             pass the .databases attribute set on the first DB added to the
  319.             collection.
  320.         """
  321.         pass
  322.  
  323.     databases = Attribute('        A mapping from database name to DB (database) object.\n\n        In multi-database use, all DB members of a database collection share\n        the same .databases object.\n\n        In single-database use, of course this mapping contains a single\n        entry.\n        ')
  324.  
  325.  
  326. class IStorage(Interface):
  327.     '''A storage is responsible for storing and retrieving data of objects.
  328.     '''
  329.     pass
  330.  
  331.  
  332. class IStorageUndoable(IStorage):
  333.     '''A storage supporting transactional undo.
  334.     '''
  335.     
  336.     def undo(transaction_id, txn):
  337.         '''TODO'''
  338.         pass
  339.  
  340.     
  341.     def undoLog(first, last, filter = (lambda desc: True)):
  342.         '''Return a sequence of descriptions for undoable transactions.
  343.  
  344.         Application code should call undoLog() on a DB instance instead of on
  345.         the storage directly.
  346.  
  347.         A transaction description is a mapping with at least these keys:
  348.  
  349.             "time":  The time, as float seconds since the epoch, when
  350.                      the transaction committed.
  351.             "user_name":  The value of the `.user` attribute on that
  352.                           transaction.
  353.             "description":  The value of the `.description` attribute on
  354.                             that transaction.
  355.             "id`"  A string uniquely identifying the transaction to the
  356.                    storage.  If it\'s desired to undo this transaction,
  357.                    this is the `transaction_id` to pass to `undo()`.
  358.  
  359.         In addition, if any name+value pairs were added to the transaction
  360.         by `setExtendedInfo()`, those may be added to the transaction
  361.         description mapping too (for example, FileStorage\'s `undoLog()` does
  362.         this).
  363.  
  364.         `filter` is a callable, taking one argument.  A transaction
  365.         description mapping is passed to `filter` for each potentially
  366.         undoable transaction.  The sequence returned by `undoLog()` excludes
  367.         descriptions for which `filter` returns a false value.  By default,
  368.         `filter` always returns a true value.
  369.  
  370.         ZEO note:  Arbitrary callables cannot be passed from a ZEO client
  371.         to a ZEO server, and a ZEO client\'s implementation of `undoLog()`
  372.         ignores any `filter` argument that may be passed.  ZEO clients
  373.         should use the related `undoInfo()` method instead (if they want
  374.         to do filtering).
  375.  
  376.         Now picture a list containing descriptions of all undoable
  377.         transactions that pass the filter, most recent transaction first (at
  378.         index 0).  The `first` and `last` arguments specify the slice of this
  379.         (conceptual) list to be returned:
  380.  
  381.             `first`:  This is the index of the first transaction description
  382.                       in the slice.  It must be >= 0.
  383.             `last`:  If >= 0, first:last acts like a Python slice, selecting
  384.                      the descriptions at indices `first`, first+1, ..., up to
  385.                      but not including index `last`.  At most last-first
  386.                      descriptions are in the slice, and `last` should be at
  387.                      least as large as `first` in this case.  If `last` is
  388.                      less than 0, then abs(last) is taken to be the maximum
  389.                      number of descriptions in the slice (which still begins
  390.                      at index `first`).  When `last` < 0, the same effect
  391.                      could be gotten by passing the positive first-last for
  392.                      `last` instead.
  393.         '''
  394.         pass
  395.  
  396.     
  397.     def undoInfo(first, last, specification = None):
  398.         '''Return a sequence of descriptions for undoable transactions.
  399.  
  400.         This is like `undoLog()`, except for the `specification` argument.
  401.         If given, `specification` is a dictionary, and `undoInfo()`
  402.         synthesizes a `filter` function `f` for `undoLog()` such that
  403.         `f(desc)` returns true for a transaction description mapping
  404.         `desc` if and only if `desc` maps each key in `specification` to
  405.         the same value `specification` maps that key to.  In other words,
  406.         only extensions (or supersets) of `specification` match.
  407.  
  408.         ZEO note:  `undoInfo()` passes the `specification` argument from a
  409.         ZEO client to its ZEO server (while a ZEO client ignores any `filter`
  410.         argument passed to `undoLog()`).
  411.         '''
  412.         pass
  413.  
  414.     
  415.     def pack(t, referencesf):
  416.         '''TODO'''
  417.         pass
  418.  
  419.  
  420.  
  421. class IStorageVersioning(IStorage):
  422.     '''A storage supporting versions.
  423.     '''
  424.     pass
  425.  
  426.